#include <random>
#include "ringbuffer_global.h"
#include <iostream>

int main()
{
    for (int tc = 0; tc < 100000; ++tc)
    {
        std::mt19937 generator(std::random_device{}());
        std::mt19937 generatorchar(std::random_device{}());
        std::mt19937 generatorOutlen(std::random_device{}());
        // 创建一个均匀分布
        std::uniform_int_distribution<int> distribution(0, 512);
        std::uniform_int_distribution<int> distributionchar(0, 255);
        unsigned int random_len = distribution(generator);
        std::uniform_int_distribution<int> distributionOutlen(0, random_len);
        unsigned int outlen = distributionOutlen(generatorOutlen);
        unsigned char *pdata = new unsigned char[random_len];
        unsigned char *pdataOut = new unsigned char[outlen];

        for (size_t i = 0; i < random_len; i++)
        {
            pdata[i] = distributionchar(generatorchar);
        }
        RingBufferCreator b;
        RingBuffer* a = b.Generate(random_len);
        a->PushData(pdata, random_len);
        unsigned long long res = a->PopData(pdataOut, outlen);
        if (res != outlen)
        {
            std::cout << "err" << std::endl;
            return 1;
        }
        else
        {
            std::cout<<res<<" ";            
        }
        for (int j = 0; j < res; ++j)
        {
            if (pdata[j] != pdataOut[j])
            {
                std::cout << "no eq" << std::endl;
                return 1;
            }
            else
            {
                //std::cout<<pdata[j];
            }
        }
        //std::cout<<"endl"<<std::endl;
        delete[] pdata;
        delete[] pdataOut;
        b.Destroy(a);
       // std::cout << "fni" << std::endl;
    }
}